package com.example.certificate.controller;


import com.example.certificate.annoatiton.CurrentUser;
import com.example.certificate.annoatiton.LoginToken;
import com.example.certificate.dto.BasePageDTO;
import com.example.certificate.dto.InsResourceDto;
import com.example.certificate.dto.common.DelByIdDto;
import com.example.certificate.dto.common.DisableStatDto;
import com.example.certificate.entity.SysResource;
import com.example.certificate.entity.User;
import com.example.certificate.execption.BusinessException;
import com.example.certificate.service.SysResourceService;
import com.example.certificate.utils.ResultEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.ir.annotations.Ignore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 菜单表	 前端控制器
 * </p>
 *
 * @author hao
 * @since 2022-02-16 11:29:59
 */
@RestController
@RequestMapping("/domain/sysResource")
@Api(tags = {"前端路由页面"}, value = "/domain/sysResource")
public class SysResourceController {

    @Autowired
    private SysResourceService resourceService;


    @ApiOperation(value = "查询路由")
    @LoginToken
    @GetMapping(value = "/routingHop")
    public ResultEntity routingHop(@CurrentUser @Ignore User user){
        return new ResultEntity(resourceService.routingHop(user));
    }


    @ApiOperation(value = "设置新路由")
    @LoginToken
    @PostMapping(value = "/insSysResource")
    public ResultEntity insSysResource(@RequestBody InsResourceDto dto, @Ignore @CurrentUser User user) throws BusinessException { return resourceService.insSysResource(dto);}


    @ApiOperation(value = "查询所有路由信息")
    @LoginToken
    @GetMapping(value = "/selAllRouter")
    public ResultEntity selAllRouter(){ return new ResultEntity(resourceService.selAllRouter());}


    @GetMapping(value = "/getTreeResource")
    @LoginToken
    @ApiOperation(value = "查询路由树形控件")
    public ResultEntity getTreeResource(){
        return new ResultEntity(resourceService.getTreeResource());
    }

    @PostMapping(value = "/getRouterById")
    @LoginToken
    @ApiOperation(value = "根据id获取路由的具体信息")
    public ResultEntity getRouterById(@Validated(value = {DelByIdDto.delDataById.class}) @RequestBody DelByIdDto dto){
        return new ResultEntity(resourceService.getResourceById(dto));
    }

    @LoginToken
    @PostMapping(value = "/getResourcePage")
    @ApiOperation(value = "分页查询菜单数据")
    public ResultEntity getResourcePage(@RequestBody BasePageDTO dto){
        return new ResultEntity(resourceService.getResourcePage(dto));
    }


    @LoginToken
    @ApiOperation(value = "修改路由状态")
    @PostMapping(value = "/updateResourceStatus")
    public ResultEntity updateResourceStatus(@Validated(value = {DisableStatDto.disableStatus.class}) @RequestBody DisableStatDto dto){
        return resourceService.updateStatus(dto);
    }


    @LoginToken
    @ApiOperation(value = "删除路由设置")
    @PostMapping(value = "/delResourceById")
    public ResultEntity delById(@Validated(value = {DelByIdDto.delDataById.class}) @RequestBody DelByIdDto dto){
        return resourceService.delById(dto);
    }

    @LoginToken
    @ApiOperation(value = "修改菜单路由信息")
    @PostMapping(value = "/updateResource")
    public ResultEntity updateResource(@RequestBody SysResource resource, @Ignore @CurrentUser User user){
        return resourceService.updateResource(resource);
    }

    @LoginToken
    @ApiOperation(value = "菜单权限分配")
    @GetMapping(value = "/getAuthAllocation")
    public ResultEntity getAuthAllocation(){
        return new ResultEntity(resourceService.getAuthAllocation());
    }
}

